/**
Copyright: Copyright (c) 2017-2019 Andrey Penechko.
License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Andrey Penechko.
*/
module be.asmtest.cmp;

import be.asmtest.utils;

void testCmp(CodegenTester tester)
{
	// Cmp reg8, reg8
	foreach (Register regA; Register.min..RegisterMax) tester.cmpb(regA, Register.min);
	foreach (Register regB; Register.min..RegisterMax) tester.cmpb(Register.min, regB);
	tester.assertHexAndReset("38C038C138C238C34038C44038C54038C64038C74138C04138C14138C24138C34138C44138C54138C64138C738C038C838D038D84038E04038E84038F04038F84438C04438C84438D04438D84438E04438E84438F04438F8");

	// Cmp reg16, reg16
	foreach (Register regA; Register.min..RegisterMax) tester.cmpw(regA, Register.min);
	foreach (Register regB; Register.min..RegisterMax) tester.cmpw(Register.min, regB);
	tester.assertHexAndReset("6639C06639C16639C26639C36639C46639C56639C66639C7664139C0664139C1664139C2664139C3664139C4664139C5664139C6664139C76639C06639C86639D06639D86639E06639E86639F06639F8664439C0664439C8664439D0664439D8664439E0664439E8664439F0664439F8");

	// Cmp reg32, reg32
	foreach (Register regA; Register.min..RegisterMax) tester.cmpd(regA, Register.min);
	foreach (Register regB; Register.min..RegisterMax) tester.cmpd(Register.min, regB);
	tester.assertHexAndReset("39C039C139C239C339C439C539C639C74139C04139C14139C24139C34139C44139C54139C64139C739C039C839D039D839E039E839F039F84439C04439C84439D04439D84439E04439E84439F04439F8");

	// Cmp reg64, reg64
	foreach (Register regA; Register.min..RegisterMax) tester.cmpq(regA, Register.min);
	foreach (Register regB; Register.min..RegisterMax) tester.cmpq(Register.min, regB);
	tester.assertHexAndReset("4839C04839C14839C24839C34839C44839C54839C64839C74939C04939C14939C24939C34939C44939C54939C64939C74839C04839C84839D04839D84839E04839E84839F04839F84C39C04C39C84C39D04C39D84C39E04C39E84C39F04C39F8");

	// Cmp reg8, imm8
	foreach (Register regA; Register.min..RegisterMax) tester.cmpb(regA, Imm8(0x24));
	tester.assertHexAndReset("80F82480F92480FA2480FB244080FC244080FD244080FE244080FF244180F8244180F9244180FA244180FB244180FC244180FD244180FE244180FF24");

	// Cmp reg16, imm8
	foreach (Register regA; Register.min..RegisterMax) tester.cmpw(regA, Imm8(0x24));
	tester.assertHexAndReset("6683F8246683F9246683FA246683FB246683FC246683FD246683FE246683FF24664183F824664183F924664183FA24664183FB24664183FC24664183FD24664183FE24664183FF24");

	// Cmp reg32, imm8
	foreach (Register regA; Register.min..RegisterMax) tester.cmpd(regA, Imm8(0x24));
	tester.assertHexAndReset("83F82483F92483FA2483FB2483FC2483FD2483FE2483FF244183F8244183F9244183FA244183FB244183FC244183FD244183FE244183FF24");

	// Cmp reg64, imm8
	foreach (Register regA; Register.min..RegisterMax) tester.cmpq(regA, Imm8(0x24));
	tester.assertHexAndReset("4883F8244883F9244883FA244883FB244883FC244883FD244883FE244883FF244983F8244983F9244983FA244983FB244983FC244983FD244983FE244983FF24");

	// Cmp reg16, imm16
	foreach (Register regA; Register.min..RegisterMax) tester.cmpw(regA, Imm16(0x2436));
	tester.assertHexAndReset("6681F836246681F936246681FA36246681FB36246681FC36246681FD36246681FE36246681FF3624664181F83624664181F93624664181FA3624664181FB3624664181FC3624664181FD3624664181FE3624664181FF3624");

	// Cmp reg32, imm32
	foreach (Register regA; Register.min..RegisterMax) tester.cmpd(regA, Imm32(0x24364758));
	tester.assertHexAndReset("81F85847362481F95847362481FA5847362481FB5847362481FC5847362481FD5847362481FE5847362481FF584736244181F8584736244181F9584736244181FA584736244181FB584736244181FC584736244181FD584736244181FE584736244181FF58473624");

	// Cmp reg64, imm64
	foreach (Register regA; Register.min..RegisterMax) tester.cmpq(regA, Imm32(0x24364758));
	tester.assertHexAndReset("4881F8584736244881F9584736244881FA584736244881FB584736244881FC584736244881FD584736244881FE584736244881FF584736244981F8584736244981F9584736244981FA584736244981FB584736244981FC584736244981FD584736244981FE584736244981FF58473624");
}
